main = function(){
    if(viewer == null){
        document.location = '#auth';
    }else{
        document.location = '#main/index';
    }
}

main.index = function(){
    main.init();
    $('#menu-bar').html('');
    $('#content').html(fly.template('http://naima.vn/index.html', {
        menu:main.menu
    }));
}

main.init = function(){
    if(viewer == null){
        document.location = '#auth';
    }
    $('body').html(fly.template('http://naima.vn/main.html')).keypress(function(e){
        if(e.keyCode == 27){
            $('.popup-close').click();
        }
    });
    $('#tp-right-panel').html('<p><a href="#main/index">Trang chủ quản trị</a> | <a target="_blank" href="'+fly.baseUrl+'/">Trang chủ Naima.vn</a> | <a href="#auth/signout">Đăng xuất</a> (<span style="color:#d9251d;">'+viewer.username+'</span>)</p>');
    if(!main.menu){
        fly.ajax({
            service:'/menu/get', 
            success:function(result){
                if(result.status){
                    main.menu = result.data;
                }
            }, 
            async:false
        });
    }
    $('#menu-bar').html(fly.template('http://naima.vn/menu.html', {
        menu:main.menu
    }));
}
cache = {};
cache.flush = function(){
    fly.ajax({
        service:'/cache/flush', 
        success:function(result){
            alert(result.message);
            history.go(-1);
        }
    });
}
Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep){ 
    var n = this,
    c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
    d = decimal_sep || '.', //if no decimal separator is passed we use the dot as default decimal separator (we MUST use a decimal separator)

    t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want to use a thousands separator you can pass empty string as thousands_sep value

    sign = (n < 0) ? '-' : '',

    //extracting the absolute value of the integer part of the number and converting to string
    i = parseInt(n = Math.abs(n).toFixed(c)) + '', 

    j = ((j = i.length) > 3) ? j % 3 : 0; 
    return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ''); 
}